﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IllustratedCsharp7_ch20_Linq
{
    class chapt20_5_6SelectGroupClause
    {
        static void _Main()
        {
            var students = new[] //匿名类型的对象数组
           {
                    new { LName="Jones",    FName="Mary",   Age=19,Major="History" },
                    new { LName="Smith",    FName="Bob",    Age=20,Major="CompSci" },
                    new { LName="Fleming",  FName="Carol",  Age=21,Major="History" }
            };

            var query = from student in students
                        group student by student.Major;

            foreach (var g in query)                //枚举分组
            {
                Console.WriteLine("{0}", g.Key);    //分组键

                foreach (var s in g)                //枚举分组中的项
                    Console.WriteLine($"      { s.LName },{ s.FName }");
            }
        }
    }
}
